package com.ruoyi.vehicle.service.impl;

import java.util.List;

import com.ruoyi.common.core.web.domain.AjaxResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import com.ruoyi.vehicle.mapper.SysVehicleMapper;
import com.ruoyi.vehicle.domain.SysVehicle;
import com.ruoyi.vehicle.service.ISysVehicleService;

import javax.annotation.PostConstruct;

/**
 * 车辆信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-10-13
 */
@Slf4j
@Service
public class SysVehicleServiceImpl implements ISysVehicleService
{
    @Autowired
    private SysVehicleMapper sysVehicleMapper;
    @Autowired
    RedisTemplate redisTemplate;

    /**
     * 查询车辆信息
     *
     * @param vehicleId 车辆信息主键
     * @return 车辆信息
     */
    @Override
    public SysVehicle selectSysVehicleByVehicleId(Integer vehicleId)
    {
        return sysVehicleMapper.selectSysVehicleByVehicleId(vehicleId);
    }

    /**
     * 查询车辆信息列表
     *
     * @param sysVehicle 车辆信息
     * @return 车辆信息
     */
    @Override
    public List<SysVehicle> selectSysVehicleList(SysVehicle sysVehicle)
    {
        return sysVehicleMapper.selectSysVehicleList(sysVehicle);
    }

    /**
     * 新增车辆信息
     *
     * @param sysVehicle 车辆信息
     * @return 结果
     */
    @Override
    public int insertSysVehicle(SysVehicle sysVehicle)
    {
        return sysVehicleMapper.insertSysVehicle(sysVehicle);
    }

    /**
     * 修改车辆信息
     *
     * @param sysVehicle 车辆信息
     * @return 结果
     */
    @Override
    public int updateSysVehicle(SysVehicle sysVehicle)
    {
        return sysVehicleMapper.updateSysVehicle(sysVehicle);
    }

    /**
     * 批量删除车辆信息
     *
     * @param vehicleIds 需要删除的车辆信息主键
     * @return 结果
     */
    @Override
    public int deleteSysVehicleByVehicleIds(Integer[] vehicleIds)
    {
        return sysVehicleMapper.deleteSysVehicleByVehicleIds(vehicleIds);
    }

    /**
     * 删除车辆信息信息
     *
     * @param vehicleId 车辆信息主键
     * @return 结果
     */
    @Override
    public int deleteSysVehicleByVehicleId(Integer vehicleId)
    {
        return sysVehicleMapper.deleteSysVehicleByVehicleId(vehicleId);
    }

    @PostConstruct
    public AjaxResult selectSysVehicleListByUserId()
    {
        redisTemplate.delete("vehicleCount");
        redisTemplate.delete("vehicleModel");
        // 查询车辆总数
       int count =  sysVehicleMapper.selectSysVehicle();
       redisTemplate.opsForValue().set("vehicleCount",count);
        //查询各型号统计
        List<SysVehicle> list = sysVehicleMapper.selectSysVehicleListByVehicleModel();

       redisTemplate.opsForValue().set("vehicleModel",list);

       log.info("redis存储成功");

      return AjaxResult.success("redis存储成功");
    }
}
